package com.midian.controller.advice;

import java.io.File;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;

import com.midian.service.advice.IAdviceService;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.midian.common.filter.annotation.Validate;
import com.midian.common.pager.Pager;
import com.midian.common.system.ErrorConstants;
import com.midian.common.system.RetManager;
import com.midian.common.utils.ObjUtils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 反馈意见控制器
 *
 */
@Controller("adviceController")
public class AdviceController {
	/**日志*/
	private static Logger LOG = Logger.getLogger(AdviceController.class);
	/**反馈意见业务*/
	private IAdviceService adviceService;

	@Resource(name="adviceService")
	public void setAdviceService(IAdviceService adviceService) {
		this.adviceService = adviceService;
	}
	
	/**
	 * 反馈
	 * @param client_key
	 * @param user_id
	 * @param access_token
	 * @param content
	 * @return
	 * @throws Exception
	 */
	@Validate(retCode = RetManager.common_save_error)
	@RequestMapping(value = "/advice", method = RequestMethod.POST)
	public @ResponseBody Object Advice(String client_key, @RequestParam(required=false) String user_id, 
			@RequestParam(required=false) String access_token,String content
			 ) throws Exception {
		JSONObject json = new JSONObject();
		try {
			com.midian.model.advice.Advice advice = new com.midian.model.advice.Advice();
			advice.setUserId(user_id);
			advice.setContent(content);
			this.adviceService.add(advice);
		} catch (Exception e) {
			LOG.error(e.getMessage());
		    throw e;
		}
        RetManager.getInstance().setRetSuccess(json, RetManager.common_submit_success);
		return json;
	}
}
